#!/usr/bin/env python

from unit import *
from parse import *

# Here define global parameter
config_name = None
step = None
freq_mode = None
kmax = None
cal_start = None
cal_end = None
plot_start = None
plot_end = None
iteration = None
static_function = None

temperature = None
density_mode = None
kondon = None
delta0 = None
epsi = None
cutoff_freq = None
lamda = None
gamma = None
init_state = None
delta0_deviation = None
epsi_deviation = None
recal_w0 = None
pulse_signal = None
pulse_time = None
delta0_extra = None
epsi_extra = None



system_parameters = []
env_parameters = []
cal_range = []
plot_range = []


# parse the simulation parameters
key_value = parse("quapi.conf")


# now we correlate variable name and dict key
config_name = key_value["config_name"]
step = float(key_value["step"])
freq_mode = int(key_value["freq_mode"])
kmax = int(key_value["kmax"])

cal_start = float(key_value["cal_start"])
cal_end = float(key_value["cal_end"])
cal_range.extend([cal_start, cal_end])

plot_start = float(key_value["plot_start"])
plot_end = float(key_value["plot_end"])
cal_range.extend([plot_start, plot_end])

iteration = int(key_value["iteration"])
if iteration > 1 and key_value["static_function"] == "on" and config_name != "None":
	static_function = 1
else:
	static_function = 0
temperature = float(key_value["temperature"])
density_mode = int(key_value["density_mode"])
kondon = float(key_value["kondon"])
if key_value["pulse_signal"] == "on":
	pulse_signal = 1
else:
	pulse_signal = 0
	
if pulse_signal == 1:
	pulse_time = float(key_value["pulse_time"])
else:
	pulse_time = None


if freq_mode == 0:
	# In this mode, international standard unit is used.
	delta0 = float(key_value["delta0"])
	epsi = float(key_value["epsi"])
	cutoff_freq = float(key_value["cutoff_freq"])
	lamda = float(key_value["lamda"])
	gamma = float(key_value["gamma"])
	delta0_deviation = float(key_value["delta0_deviation"])
	epsi_deviation = float(key_value["epsi_deviation"])
	delta0_extra = float(key_value["delta0_extra"])
	epsi_extra = float(key_value["epsi_extra"])
elif freq_mode == 1:
	pass		
else:
	# In this mode, all freq numerical value should be transformed from cm-1 to s-1
	delta0 = cm_to_freq(float(key_value["delta0"]))
	epsi = cm_to_freq(float(key_value["epsi"]))
	cutoff_freq = cm_to_freq(float(key_value["cutoff_freq"]))
	lamda = cm_to_freq(float(key_value["lamda"]))
	gamma = cm_to_freq(float(key_value["gamma"]))
	delta0_deviation = cm_to_freq(float(key_value["delta0_deviation"]))
	epsi_deviation = cm_to_freq(float(key_value["epsi_deviation"])		)
	delta0_extra = cm_to_freq(float(key_value["delta0_extra"]))
	epsi_extra = cm_to_freq(float(key_value["epsi_extra"]))
if epsi_deviation == 0 and delta0_deviation == 0:
	recal_w0 = 0
else:
	recal_w0 = int(key_value["recal_w0"])	
	


env_parameters.append(density_mode)
if density_mode == 0:
	env_parameters.append(lamda)
	env_parameters.append(gamma)
	env_parameters.append(cutoff_freq)
else:
	env_parameters.append(kondon)
	env_parameters.append(cutoff_freq)
init_state = int(key_value["init_state"])
system_parameters.append(delta0)
system_parameters.append(epsi)
system_parameters.append(delta0_deviation)
system_parameters.append(epsi_deviation)
	
	

